﻿using PanhuaWin.通用;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PanhuaWin.工厂.仓库.下线;
using PanhuaWin.工厂.仓库.超级管理员;
using PanhuaWin.出库管理;
using PanhuaWin.工厂.车间;
using PanhuaWin.工厂.仓库.原料辅材推送NC;
using PanhuaWin.工厂.仓库.生产领用;
using PanhuaWin.工厂.车间.报工;
using PanhuaWin.工厂.仓库.报表;
using PanhuaWin.仓库.下线;
using PanhuaWin.超级管理员;

namespace PanhuaWin
{
    public partial class FormMain : UIAsideHeaderMainFrame
    {
        public FormMain()
        {
            InitializeComponent();
            this.Text = Application.ProductName + " " + Application.ProductVersion;
            this.WindowState = FormWindowState.Maximized;
            int pageIndex = 1000;
            TreeNode parent = Aside.CreateNode("功能菜单", 61451, 24, pageIndex);
            TreeNode TreeNode_仓库业务 = parent.Nodes.Add("仓库业务");
            TreeNode TreeNode_入库业务 = TreeNode_仓库业务.Nodes.Add("入库业务");
            TreeNode TreeNode_超级管理员 = parent.Nodes.Add("超级管理员");
            TreeNode TreeNode_出库业务 = TreeNode_仓库业务.Nodes.Add("出库业务");
            if (UserAuth("原料卷入库", "Plan"))
            {
                Aside.CreateChildNode(TreeNode_入库业务, 1, 1, AddPage(new 仓库.采购入库.Form原料卷入库(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_入库业务, 1, 2, AddPage(new 仓库.采购入库.Form原料卷入库审核(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_出库业务, 1, 1, AddPage(new 仓库.生产领用.Form原料卷领用(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_出库业务, 1, 3, AddPage(new Form原料卷推送NC(), Guid.NewGuid()));
            }
            //Aside.CreateChildNode(TreeNode_入库业务, 1, 3, AddPage(new 仓库.采购入库.Form卷号转换(), Guid.NewGuid()));
            if (UserAuth("原料卷入库", "Plan"))
            {
                Aside.CreateChildNode(TreeNode_入库业务, 1, 4, AddPage(new 仓库.采购入库.Form辅材入库(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_入库业务, 1, 5, AddPage(new 仓库.采购入库.Form辅材入库审核(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_出库业务, 1, 2, AddPage(new 仓库.生产领用.Form辅材领用(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_出库业务, 1, 3, AddPage(new Form辅材推送NC(), Guid.NewGuid()));
            }

            if (UserAuth("大标签打印记录", "Search") || UserAuth("原料卷入库", "Plan") || UserAuth("NC销售发货单", "Delete"))
            {
                //Aside.CreateChildNode(TreeNode_入库业务, 1, 5, AddPage(new 仓库.下线.Form打印标签(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_入库业务, 1, 6, AddPage(new Form补录存货编码(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_入库业务, 1, 6, AddPage(new 仓库.下线.Form大标签打印(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_入库业务, 1, 6, AddPage(new Form外贸打印(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_入库业务, 1, 6, AddPage(new Form仓库转移(), Guid.NewGuid()));
                //Aside.CreateChildNode(TreeNode_入库业务, 1, 8, AddPage(new Form岳阳标签临时打印(), Guid.NewGuid()));
                //Aside.CreateChildNode(TreeNode_入库业务, 1, 5, AddPage(new 仓库.下线.Form临时大标签打印(), Guid.NewGuid()));
            }
            Aside.CreateChildNode(TreeNode_入库业务, 1, 7, AddPage(new 仓库.下线.Form小标签临时打印(), Guid.NewGuid()));




            TreeNode TreeNode_库存报表 = TreeNode_仓库业务.Nodes.Add("库存报表");
            Aside.CreateChildNode(TreeNode_库存报表, 1, 1, AddPage(new 仓库.报表.Form库存余额报表(), Guid.NewGuid()));
            Aside.CreateChildNode(TreeNode_库存报表, 1, 2, AddPage(new Form投入产出汇总(), Guid.NewGuid()));

            TreeNode TreeNode_车间计划 = parent.Nodes.Add("车间计划");
            if (UserAuth("计划", "Search"))
            {
                TreeNode TreeNode_酸洗计划 = TreeNode_车间计划.Nodes.Add("酸洗计划");
                Aside.CreateChildNode(TreeNode_酸洗计划, 1, 1, AddPage(new 车间.Form酸洗计划维护(), Guid.NewGuid()));

                TreeNode TreeNode_轧硬计划 = TreeNode_车间计划.Nodes.Add("轧硬计划");
                Aside.CreateChildNode(TreeNode_轧硬计划, 1, 1, AddPage(new 车间.Form轧硬计划维护(), Guid.NewGuid()));
            
            //Aside.CreateChildNode(TreeNode_轧硬计划, 1, 2, AddPage(new 车间.Form轧硬计划报表(), Guid.NewGuid()));
                TreeNode TreeNode_镀锌计划 = TreeNode_车间计划.Nodes.Add("镀锌计划");
                Aside.CreateChildNode(TreeNode_镀锌计划, 1, 1, AddPage(new 车间.Form镀锌计划维护(), Guid.NewGuid()));
            }
            //if (UserAuth("彩涂计划", "Plan"))
            //{
            //    TreeNode TreeNode_彩涂计划 = TreeNode_车间计划.Nodes.Add("彩涂计划");
            //    Aside.CreateChildNode(TreeNode_彩涂计划, 1, 1, AddPage(new 车间.Form彩涂计划维护(), Guid.NewGuid()));
            //}
            //if (UserAuth("退火计划", "Plan"))
            //{
            //    TreeNode TreeNode_退火计划 = TreeNode_车间计划.Nodes.Add("退火计划");
            //    Aside.CreateChildNode(TreeNode_退火计划, 1, 1, AddPage(new 车间.Form退火计划维护(), Guid.NewGuid()));
            //}
            //if (UserAuth("罩退计划", "Plan"))
            //{
            //    TreeNode TreeNode_罩退计划 = TreeNode_车间计划.Nodes.Add("罩退计划");
            //    Aside.CreateChildNode(TreeNode_罩退计划, 1, 1, AddPage(new 车间.Form罩退计划维护(), Guid.NewGuid()));
            //}
            //if (UserAuth("硅钢计划", "Plan"))
            //{
            //    TreeNode TreeNode_硅钢计划 = TreeNode_车间计划.Nodes.Add("硅钢计划");
            //    Aside.CreateChildNode(TreeNode_硅钢计划, 1, 1, AddPage(new 车间.Form硅钢计划维护(), Guid.NewGuid()));
            //}
            TreeNode TreeNode_车间业务 = parent.Nodes.Add("车间业务");
            if (UserAuth("酸洗报工", "BaoGong") || UserAuth("生产领导", "Search"))
            {
                TreeNode TreeNode_酸洗 = TreeNode_车间业务.Nodes.Add("酸洗工序");

                Aside.CreateChildNode(TreeNode_酸洗, 1, 1, AddPage(new 车间.酸洗.Form酸洗报工维护(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_酸洗, 1, 2, AddPage(new 车间.Form酸洗投入产出表(), Guid.NewGuid()));

            }
            if (UserAuth("轧硬报工", "BaoGong") || UserAuth("生产领导", "Search"))
            {

                TreeNode TreeNode_轧硬 = TreeNode_车间业务.Nodes.Add("轧硬工序");
                Aside.CreateChildNode(TreeNode_轧硬, 1, 1, AddPage(new 车间.轧硬.Form轧硬报工维护(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_轧硬, 1, 2, AddPage(new 车间.Form轧硬投入产出表(), Guid.NewGuid()));
            }
            if (UserAuth("镀锌报工", "BaoGong") || UserAuth("生产领导", "Search"))
            {
                TreeNode TreeNode_镀锌 = TreeNode_车间业务.Nodes.Add("镀锌工序");
                Aside.CreateChildNode(TreeNode_镀锌, 1, 1, AddPage(new 车间.镀锌.Form镀锌报工维护(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_镀锌, 1, 2, AddPage(new 车间.Form镀锌投入产出表(), Guid.NewGuid()));
            } 
            if (UserAuth("镀铝锌报工", "BaoGong") || UserAuth("生产领导", "Search"))
            {
                TreeNode TreeNode_镀铝锌 = TreeNode_车间业务.Nodes.Add("镀铝锌工序");
                Aside.CreateChildNode(TreeNode_镀铝锌, 1, 1, AddPage(new Form镀铝锌报工维护(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_镀铝锌, 1, 2, AddPage(new Form镀铝锌投入产出表(), Guid.NewGuid()));
            }
            //if (UserAuth("彩涂报工", "BaoGong"))
            //{
            //    TreeNode TreeNode_彩涂 = TreeNode_车间业务.Nodes.Add("彩涂工序");
            //    Aside.CreateChildNode(TreeNode_彩涂, 1, 1, AddPage(new 车间.彩涂.Form彩涂报工维护(), Guid.NewGuid()));
            //    Aside.CreateChildNode(TreeNode_彩涂, 1, 2, AddPage(new 车间.Form彩涂投入产出表(), Guid.NewGuid()));
            //}
            //if (UserAuth("罩退报工", "BaoGong"))
            //{
            //    TreeNode TreeNode_罩退 = TreeNode_车间业务.Nodes.Add("罩退工序");
            //    Aside.CreateChildNode(TreeNode_罩退, 1, 1, AddPage(new 车间.罩退.Form罩退报工维护(), Guid.NewGuid()));
            //    Aside.CreateChildNode(TreeNode_罩退, 1, 2, AddPage(new Form罩退投入产出表(), Guid.NewGuid()));
            //    //Aside.CreateChildNode(TreeNode_退火, 1, 2, AddPage(new 车间.退火.Form退火报工报表(), Guid.NewGuid()));
            //}
            //if (UserAuth("退火报工", "BaoGong"))
            //{
            //    TreeNode TreeNode_退火 = TreeNode_车间业务.Nodes.Add("退火工序");
            //    Aside.CreateChildNode(TreeNode_退火, 1, 1, AddPage(new 车间.退火.Form退火报工维护(), Guid.NewGuid()));
            //    //Aside.CreateChildNode(TreeNode_退火, 1, 2, AddPage(new 车间.退火.Form退火报工报表(), Guid.NewGuid()));
            //}
            //if (UserAuth("硅钢报工", "BaoGong"))
            //{
            //    TreeNode TreeNode_硅钢 = TreeNode_车间业务.Nodes.Add("硅钢工序");
            //    Aside.CreateChildNode(TreeNode_硅钢, 1, 1, AddPage(new 车间.硅钢.Form硅钢报工维护(), Guid.NewGuid()));
            //    //Aside.CreateChildNode(TreeNode_硅钢, 1, 2, AddPage(new 车间.硅钢.Form硅钢报工报表(), Guid.NewGuid()));
            //}

            TreeNode TreeNode_消耗产废 = TreeNode_车间业务.Nodes.Add("消耗产废");
            Aside.CreateChildNode(TreeNode_消耗产废, 1, 1, AddPage(new Form产线消耗登记(), Guid.NewGuid()));
            //Aside.CreateChildNode(TreeNode_消耗产废, 1, 2, AddPage(new Form产线消耗查询(), Guid.NewGuid()));
            //Aside.CreateChildNode(TreeNode_消耗产废, 1, 3, AddPage(new Form产线消耗确认(), Guid.NewGuid()));
            Aside.CreateChildNode(TreeNode_消耗产废, 1, 4, AddPage(new Form产线产废登记(), Guid.NewGuid()));
            //Aside.CreateChildNode(TreeNode_消耗产废, 1, 5, AddPage(new Form产线产废查询(), Guid.NewGuid()));
            //Aside.CreateChildNode(TreeNode_消耗产废, 1, 6, AddPage(new Form产线产废确认(), Guid.NewGuid()));


            //// Aside.CreateChildNode(TreeNode_酸洗, 1, 2, AddPage(new 车间.酸洗.Form酸洗报工报表(), Guid.NewGuid()));
            ////TreeNode parent = Aside.CreateNode("功能菜单", 61451, 24, pageIndex);
            ////Aside.ExpandAll();

            Aside.CreateChildNode(TreeNode_车间业务, 1, 2, AddPage(new Form查看生产情况(), Guid.NewGuid()));

            //if (pub.sys_user.UserTrueName == "袁彬鸿" || pub.sys_user.UserTrueName == "刘喜林" || pub.sys_user.UserTrueName == "超级管理员")
            //{
            //    if (pub.sys_user.UserTrueName == "刘喜林" || pub.sys_user.UserTrueName == "超级管理员")
            //    {
            //        Aside.CreateChildNode(TreeNode_超级管理员, 1, 1, AddPage(new Form修改生产情况(), Guid.NewGuid()));
            //    }
            if (UserAuth("NC销售发货单", "Delete"))
            {
                Aside.CreateChildNode(TreeNode_超级管理员, 1, 3, AddPage(new Form仓库出库(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_超级管理员, 1, 3, AddPage(new Form发货记录查询(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_超级管理员, 1, 3, AddPage(new Form盘点计划(), Guid.NewGuid()));
            }
            else
            {
                Aside.CreateChildNode(TreeNode_超级管理员, 1, 3, AddPage(new Form发货记录查询(), Guid.NewGuid()));
                Aside.CreateChildNode(TreeNode_超级管理员, 1, 3, AddPage(new Form盘点计划(), Guid.NewGuid()));
            }

            //}
        }



        private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            pub.Delete原料入库临时数据();
            pub.Delete辅料入库临时数据();
            Application.Exit();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            pub.Delete原料入库临时数据();
            pub.Delete辅料入库临时数据();
        }

        private void uiButton修改密码_Click(object sender, EventArgs e)
        {
            Form修改密码 form修改密码 = new Form修改密码();
            form修改密码.Show();
        }

        private void uiButton退出系统_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                this.labelmsg.Text = pub.GetTime();
                
            }
            catch
            {
                this.labelmsg.Text = "网络异常!";
            }

        }
        bool UserAuth(string 功能菜单,string 功能值)
        {
            string sql; 
            if(pub.sys_user.UserTrueName=="超级管理员")
            {
                return true;
            }
            sql = "select AuthValue from View_UserAuthor where MenuName='" + 功能菜单 + "' and User_Id='"+ pub.sys_user.User_Id +"' ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count >0)
            {
                string AuthValue = tb.Rows[0]["AuthValue"].ToString();
                if (AuthValue.IndexOf(功能值) >=0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
               
                return false;
            }
        }

         
    }
}
